package com.example.lianxi222.fragment.video;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.lianxi222.R;
import com.example.mvvm_base.userbean.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class VideoRecAdapter extends BaseQuickAdapter<VideoEntity.DataBean, BaseViewHolder> {
    public VideoRecAdapter(int layoutResId, @Nullable List<VideoEntity.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoEntity.DataBean dataBean) {
        //视频
        StandardGSYVideoPlayer videoPlayer =baseViewHolder.getView(R.id.video_player);
        videoPlayer.setUp(dataBean.getVideopath(),true,"");
        //作者
        baseViewHolder.setText(R.id.video_user_name,dataBean.getAuthname());
        //地址
        baseViewHolder.setText(R.id.video_address,dataBean.getAddress());
        //评论
        baseViewHolder.setText(R.id.comment_count, dataBean.getLike_count()-1110<10000? String.valueOf (dataBean.getLike_count() - 1000) :dataBean.getDianzan()+"W");
        //点赞
        baseViewHolder.setText(R.id.like_count,dataBean.getLike_count()<10000?String.valueOf(dataBean.getLike_count()):dataBean.getLike_count()+"W");

        if(dataBean.getDianzan()==0){
         baseViewHolder.setImageResource(R.id.like_icon,R.drawable.ic_xihuan);
        }else{
            baseViewHolder.setImageResource(R.id.like_icon,R.drawable.ic_xihuanred);
        }

        //头像
        ImageView iv=baseViewHolder.getView(R.id.headshot);
        Glide.with(getContext()).load(dataBean.getHeadpath()).circleCrop().into(iv);
         //文案
        baseViewHolder.setText(R.id.caption,dataBean.getCaption());
        baseViewHolder.setText(R.id.bottom_text,dataBean.getAuthname()+"的原创作品");
        //分享数量
        baseViewHolder.setText(R.id.video_share_count,"1.6W");
        baseViewHolder.setText(R.id.collection_count,"2.0W");
        //动画
        ImageView video_button=baseViewHolder.getView(R.id.video_circle);
        Glide.with(getContext()).load(dataBean.getHeadpath()).circleCrop().into(video_button);
        ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(video_button,"rotation",0,360);
        objectAnimator.setDuration(5000);
        objectAnimator.setInterpolator(new LinearInterpolator());
        objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
        objectAnimator.start();
        //关注
        ImageView addButton=baseViewHolder.getView(R.id.video_add);
        if(dataBean.getGuanzhu()==0){
            addButton.setVisibility(View.VISIBLE);
        }else{
            addButton.setVisibility(View.GONE);
        }

    }
}
